﻿var loadLocation = function(scheduleTypeElement, beginLocationElement, endLocationElement) {
    $(scheduleTypeElement).change(function() {
        var scheduleType = $(scheduleTypeElement).val();
        $.ajax({
            type: "POST",
            url: "/ajax.html",
            data: { "function": "LocationListByScheduleType", "ScheduleType": scheduleType},
            dataType: "json",
            success: function (data) {
                
                $(beginLocationElement).html('<option value="-1">--- Chọn điểm đi ---</option>');
                $(endLocationElement).html('<option value="-1">--- Chọn điểm đến ---</option>');

                if (data && data.isError == false) {
                    $.each(data.array, function (index, item) {
                        $(beginLocationElement)
                            .append($("<option></option>")
                                .attr("value", item.ID)
                                .text(item.Name));
                        
                        $(endLocationElement)
                            .append($("<option></option>")
                                .attr("value", item.ID)
                                .text(item.Name));
                    });
                }
            }
        });
       
    });
};
var loadLocationByLocationType = function (locationTypeElement, locationElement) {
    $(locationTypeElement).change(function () { 
        var locationType =  $(locationTypeElement).val();
        $.ajax({
            type: "POST",
            url: "/ajax.html",
            data: { "function": "ListLocationByLocationType", "LocationType": locationType },
            dataType: "json",
            success: function (data) {
                $(locationElement).html('<option value="-1"> ---Chọn địa điểm--- </option>');
                if (data && data.isError == false) {
                    $.each(data.array, function (index, item) {
                        $(locationElement)
                            .append($("<option></option>")
                                .attr("value", item.ID)
                                .text(item.Name));
                    });
                }
            }
        });
    });
};
var loadCityService = function (nationalElement, provinceElement, partnerElement) {
    $(nationalElement).change(function () {
        var nationalId = $(nationalElement).val();
        
        $.ajax({
            type: "POST",
            url: "/ajax.html",
            data: { "function": "ListCityandConcernByNational", "NationalId": nationalId },
            dataType: "json",
            success: function (data) {
                $(provinceElement).html('<option value="-1"> ---Chọn tỉnh/thành phố--- </option>');
                $(partnerElement).html('<option value="-1"> ---Chọn nhà cung cấp--- </option>');
                if (data && data.isError == false) {
                    $.each(data.arrayCity, function (index, item) {
                        $(provinceElement)
                            .append($("<option></option>")
                                .attr("value", item.IDCity)
                                .text(item.NameCity));
                    });
                    $.each(data.arrayPartner, function (index, item) {
                        $(partnerElement)
                            .append($("<option></option>")
                                .attr("value", item.IDPartner)
                                .text(item.NamePartner));
                    });
                }
            }
        });
       
    });
};


